package org.datacoder.geocoding.datastructures.points

import org.datacoder.geocoding.*
import org.datacoder.geocoding.datastructures.geoshapes.*
import org.datacoder.geocoding.jurisdiction.*

class PointsSequentialScan implements PointsWithinRectangleFinder {

    GeoPoint[] geoPoints
    int length

    public PointsSequentialScan(Collection<Jurisdiction> jurisdictions){
        length = jurisdictions.size()
        geoPoints = new GeoPoint[length]
        int i = 0
        for(juris in jurisdictions){
            geoPoints[i++] = juris.toGeoPoint()
        }
    }

    public Set<Jurisdiction> findPointsWithinRectangle(GeoRectangle gr){
        Set<Jurisdiction> jurisdictions = new HashSet<Jurisdiction>()
        for(int i = 0; i < length; i++){
            if(gr.containsGeoPoint(geoPoints[i])){
                jurisdictions.add(geoPoints[i].juris)
            }
        }
        return jurisdictions
    }

}

